package com.dongchedi.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.dongchedi.service.ProductInfoService;
import com.dongchedi.utils.ResultMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author leibidong
 * @description  商品详情controller层
 * @date 2021/6/24
 */
@Controller
@RequestMapping("api")
@ResponseBody
public class ProductInfoController {
    @Autowired
    ProductInfoService productInfoService;
    /*
     * @Author: leibidong
     * @Description: 限时抢购促销商品
     * @Date: 2021/6/26 20:17
     * @Param: []
     * @Return: java.lang.String
     **/
    @GetMapping("/select/flash/sale")
    public String flashSale(){
        JSONArray jsonArray =productInfoService.hotSale(1,3);
        return ResultMessage.getJSONArrayString(1,"成功",jsonArray);
    }
    /*
     * @Author: leibidong
     * @Description: 查询商品信息
     * @Date: 2021/6/26 20:17
     * @Param: [id, customerId]
     * @Return: java.lang.String
     **/
    @GetMapping("/select/product/info")
    public String productInfo(Integer id,Integer customerId){
        JSONObject jsonObject=productInfoService.productInfo(id,customerId);
        if(!jsonObject.isEmpty()){
            return ResultMessage.getJSONObjectString(1,"查看商品详情成功",jsonObject);
        }else {
            return ResultMessage.getJSONObjectString(0,"查看商品详情失败",jsonObject);
        }
    }
    /*
     * @Author: leibidong
     * @Description: 收藏与取消收藏商品
     * @Date: 2021/6/26 20:18
     * @Param: [customerId, id, collectStatus]
     * @Return: java.lang.String
     **/
    @GetMapping("/product/collect")
    public  String collectProduct(Integer customerId,Integer id,Integer collectStatus){
        JSONObject jsonObject=productInfoService.collectStatus(customerId,id,collectStatus);
        if(!jsonObject.isEmpty()){
            return ResultMessage.getJSONObjectString(1,"收藏状态修改成功",jsonObject);
        }else {
            return ResultMessage.getJSONObjectString(0,"收藏状态修改失败",jsonObject);
        }
    }
}
